/*
 *  Copyright 2009 Anuradha.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

/*
 * TaskEditorUI.java
 *
 * Created on Jan 17, 2009, 2:38:18 PM
 */
package org.netbeans.cubeon.common.ui.internals;

import javax.swing.JComponent;
import org.netbeans.cubeon.common.ui.Group;
import org.netbeans.cubeon.common.ui.TaskEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.event.DocumentListener;
import org.openide.util.NbBundle;

/**
 *
 * @author Anuradha
 */
public class TaskEditorUI extends javax.swing.JPanel implements TaskEditor {

    private GroupEditorLayout editorLayout;

    /** Creates new form TaskEditorUI */
    public TaskEditorUI() {
        initComponents();
        if (Boolean.getBoolean("org.netbeans.cubeon.task.editor.tablayout")) {
            editorLayout = new TabBaseGroupLayout();
        } else {
            editorLayout = new TreeBaseGroupLayout();
        }
        pnlRightSide.setVisible(false);
        pnlLeftSide.setVisible(false);
    }

    public String getSummaryText() {
        return txtSummary.getText();
    }

    public void removeSummaryDocumentListener(DocumentListener listener) {
        txtSummary.getDocument().removeDocumentListener(listener);
    }

    public void addSummaryDocumentListener(DocumentListener listener) {
        txtSummary.getDocument().addDocumentListener(listener);
    }

    public void setCreatedDate(Date date) {
        final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
        String message = NbBundle.getMessage(TaskEditorUI.class,
                "TaskEditorUI.lblCreated.text", dateFormat.format(date));
        lblCreated.setText(message);
    }

    public void setUpdatedDate(Date date) {
        final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
        String message = NbBundle.getMessage(TaskEditorUI.class,
                "TaskEditorUI.lblUpdated.text", dateFormat.format(date));
        lblUpdated.setText(message);
    }

    public void setStatus(String status) {
        lblStatus.setText(NbBundle.getMessage(TaskEditorUI.class,
                "TaskEditorUI.lblStatus.text", status));
    }

    public void hideStatusLable(boolean b) {
        lblStatus.setVisible(!b);
    }

    public void hideUpdatedDateLable(boolean b) {
        lblUpdated.setVisible(!b);
    }

    public void hideCreatedDateLable(boolean b) {
        lblCreated.setVisible(!b);
    }

    public JComponent getComponent() {
        return this;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    //@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtSummary = new javax.swing.JTextField();
        lblStatus = new javax.swing.JLabel();
        lblCreated = new javax.swing.JLabel();
        lblUpdated = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        pnlLeftSide = new javax.swing.JPanel();
        pnlRightSide = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        lblStatus.setForeground(new java.awt.Color(102, 102, 102));
        lblStatus.setText(NbBundle.getMessage(TaskEditorUI.class, "TaskEditorUI.lblStatus.text","-")); // NOI18N

        lblCreated.setForeground(new java.awt.Color(102, 102, 102));
        lblCreated.setText(NbBundle.getMessage(TaskEditorUI.class, "TaskEditorUI.lblCreated.text","-")); // NOI18N

        lblUpdated.setForeground(new java.awt.Color(102, 102, 102));
        lblUpdated.setText(NbBundle.getMessage(TaskEditorUI.class, "TaskEditorUI.lblUpdated.text","-")); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(137, 140, 149)));
        jPanel1.setOpaque(false);

        pnlLeftSide.setOpaque(false);
        pnlLeftSide.setLayout(new java.awt.BorderLayout());

        pnlRightSide.setOpaque(false);
        pnlRightSide.setLayout(new java.awt.BorderLayout());

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(pnlLeftSide, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(pnlRightSide, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, pnlLeftSide, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, pnlRightSide, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(txtSummary, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 706, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(lblCreated, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 213, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(lblUpdated, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
                        .add(lblStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 215, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(8, 8, 8))))
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(txtSummary, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblUpdated)
                    .add(lblCreated)
                    .add(lblStatus))
                .addContainerGap(383, Short.MAX_VALUE))
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .add(49, 49, 49)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblCreated;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JLabel lblUpdated;
    private javax.swing.JPanel pnlLeftSide;
    private javax.swing.JPanel pnlRightSide;
    private javax.swing.JTextField txtSummary;
    // End of variables declaration//GEN-END:variables

    public void setSummaryText(String summary) {
        txtSummary.setText(summary);
    }

    public void setLeftSideGroups(Group... groups) {
        editorLayout.setLeftSideGroups(pnlLeftSide, groups);
    }

    public void setRightSideGroups(Group... groups) {
        editorLayout.setRightSideGroups(pnlRightSide, groups);
    }

    public void setRightActiveGroup(Group group) {
        editorLayout.setRightActiveGroup(group);
    }

    public void setLeftActiveGroup(Group group) {
        editorLayout.setLeftActiveGroup(group);
    }
}
